<!doctype html>
<html lang="zh-cn">
  <head>
  <meta charset="utf-8">
<title>python3 正则表达式 - Huanghs blog</title>
<meta name="viewport" content="width=device-width, initial-scale=1">


  <link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png?v=1">
  <link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png?v=1">
  <link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png?v=1">
  <link rel="manifest" href="/favicon/site.webmanifest?v=1">
  
    <link rel="mask-icon" href="/favicon/safari-pinned-tab.svg?v=1" color="#ffffff">
    <link rel="shortcut icon" href="/favicon/favicon.ico?v=1">
    <meta name="msapplication-config" content="/favicon/browserconfig.xml?v=1">
  
  <meta name="msapplication-TileColor" content="#ffffff">
  <meta name="theme-color" content="#ffffff">

<meta name="generator" content="Hugo 0.66.0" /><meta itemprop="name" content="python3 正则表达式">
<meta itemprop="description" content="展示HTML元素的基本标记语法和格式的示例文章.">
<meta itemprop="datePublished" content="2020-03-11T00:00:00&#43;00:00" />
<meta itemprop="dateModified" content="2020-03-11T00:00:00&#43;00:00" />
<meta itemprop="wordCount" content="553">
<meta itemprop="image" content="https://raw.githubusercontent.com/hhs44/cloudimg/master/img/20200313222751.png">



<meta itemprop="keywords" content="re," /><meta property="og:title" content="python3 正则表达式" />
<meta property="og:description" content="展示HTML元素的基本标记语法和格式的示例文章." />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://hhs44.github.io/blog/python3-%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/" />
<meta property="og:image" content="https://raw.githubusercontent.com/hhs44/cloudimg/master/img/20200313222751.png" />
<meta property="article:published_time" content="2020-03-11T00:00:00+00:00" />
<meta property="article:modified_time" content="2020-03-11T00:00:00+00:00" />
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://raw.githubusercontent.com/hhs44/cloudimg/master/img/20200313222751.png"/>

<meta name="twitter:title" content="python3 正则表达式"/>
<meta name="twitter:description" content="展示HTML元素的基本标记语法和格式的示例文章."/>
<meta name="twitter:site" content="@example"/>
<link rel="stylesheet" href="/css/bundle.min.b2b2abee095149a60c0a1a2c4fab4b7c140b32ca88abc3d2f83d0dd903b6f634.css" integrity="sha256-srKr7glRSaYMChosT6tLfBQLMsqIq8PS&#43;D0N2QO29jQ=">
        <link rel="stylesheet" href="/css/add-on.css">

</head>

  <body>
    
<header id="site-header">
  <nav id="site-nav">
    <h1 class="nav-title">
      <a href="/">
        
          
            博客
          
        
      </a>
    </h1>
    <menu id="site-nav-menu" class="flyout-menu">
      
        
          
          
            <a href="/" class="link"><i class='fa fa-home'></i> 首页</a>
          
        
      
        
          
          
            <a href="/blog/" class="link"><i class='far fa-newspaper'></i> 博客</a>
          
        
      
        
          
          
            <a href="/categories/" class="link"><i class='fas fa-sitemap'></i> 分类</a>
          
        
      
        
          
          
            <a href="/tags/" class="link"><i class='far fa-envelope'></i> 标签</a>
          
        
      
        
          
          
            <a href="/about/" class="link"><i class='far fa-id-card'></i> 关于</a>
          
        
      
      <a href="#share-menu" class="share-toggle"><i class="fas fa-share-alt">&nbsp;</i>Share</a>
      

    </menu>
    

    <a href="#share-menu" class="share-toggle"><i class="fas fa-share-alt fa-2x">&nbsp;</i></a>
    <a href="#lang-menu" class="lang-toggle" lang="zh-cn">zh-cn</a>
    <a href="#site-nav" class="nav-toggle"><i class="fas fa-bars fa-2x"></i></a>
  </nav>
  <menu id="lang-menu" class="flyout-menu">
  <a href="#" lang="zh-cn" class="link active">中文 (zh-cn)</a>
  
    
      
        <a href="/en" lang="en" class="no-lang link">English (en)</a>
      
    
      
    
  
</menu>

  
    <menu id="share-menu" class="flyout-menu">
      <h1>Share Post</h1>
      





    </menu>
  
</header>


    <div id="wrapper">
      <section id="site-intro">
  <a href="/"><img src="https://raw.githubusercontent.com/hhs44/cloudimg/master/img/head.jpg" class="circle" width="" alt="huang`s blog " /></a>
  <header>
    <h1>Huanghs的个人博客 </h1>
  </header>
  <main>
    <p>不写下一些东西，就没法证明自己<br> 不多走一些路，就没法看到更多的风景</p>
  </main>
  
    <footer>
      <ul class="socnet-icons">
        

        <li><a href="//github.com/hhs44/hhs44.github.io" target="_blank" rel="noopener" title="GitHub" class="fab fa-github"></a></li>






<li><a href="//flickr.com/photos/example" target="_blank" rel="noopener" title="Flickr" class="fab fa-flickr"></a></li>




<li><a href="//linkedin.com/in/example" target="_blank" rel="noopener" title="LinkedIn" class="fab fa-linkedin"></a></li>
<li><a href="//linkedin.com/company/examplebusiness" target="_blank" rel="noopener" title="LinkedIn Company" class="fab fa-linkedin"></a></li>



<li><a href="//facebook.com/example" target="_blank" rel="noopener" title="Facebook" class="fab fa-facebook"></a></li>
<li><a href="//reddit.com/user/example" target="_blank" rel="noopener" title="Reddit" class="fab fa-reddit"></a></li>





<li><a href="weixin://contacts/profile/22" target="_blank" rel="noopener" title="WeChat" class="fab fa-weixin"></a></li>
<li><a href="//wpa.qq.com/msgrd?v=3&amp;uin=1159986871&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener" title="QQ" class="fab fa-qq"></a></li>
<li><a href="//instagram.com/example" target="_blank" rel="noopener" title="Instagram" class="fab fa-instagram"></a></li>

<li><a href="//twitter.com/example" target="_blank" rel="noopener" title="Twitter" class="fab fa-twitter"></a></li>


<li><a href="//pinterest.com/example" target="_blank" rel="noopener" title="Pinterest" class="fab fa-pinterest-p"></a></li>
<li><a href="//telegram.me/example" target="_blank" rel="noopener" title="telegram" class="fab fa-telegram"></a></li>



<li><a href="//researchgate.net/profile/example" target="_blank" rel="noopener" title="Research Gate"><i class="ai ai-researchgate"></i></a></li>
<li><a href="//keybase.io/example" target="_blank" rel="noopener" title="keybase" class="fab fa-keybase"></a></li>
<li><a href="//example.com/@example" target="_blank" rel="noopener" title="mastodon" class="fab fa-mastodon"></a></li>
<li><a href="mailto:1159986871@qq.com" target="_blank" title="Email" class="far fa-envelope"></a></li>

      </ul>
    </footer>
  
</section>


      <main id="site-main">
        <article class="post">
  <header>
  <div class="title">
    
        <h2><a href="/blog/python3-%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/">python3 正则表达式</a></h2>
    
    
        <p>展示HTML元素的基本标记语法和格式的示例文章.</p>
    
</div>
  <div class="meta">
    <time class="published" datetime="2020-03-11 00:00:00 &#43;0000 UTC">
      March 11, 2020
    </time>
    <span class="author">Huanghs</span>
    
      <p>3 分钟</p>
    
  </div>
</header>

  <section id="socnet-share">
    





  </section>
  
  <a href="/blog/python3-%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/" class="image featured">
    
      <img src="https://raw.githubusercontent.com/hhs44/cloudimg/master/img/20200313222751.png" alt="">
    
  </a>


  <div class="content">
    <p>正则表达式是一个特殊的字符序列，它能帮助你方便的检查一个字符串是否与某种模式匹配。re 模块使 Python 语言拥有全部的正则表达式功能。</p>
<p>首先我们以一个案例引入：</p>
<p>用户民匹配问题：</p>
<p>要求：</p>
<ol>
<li>用户名只能包含数字 字母 下划线&gt;</li>
<li>不能以数字开头</li>
<li>长度在 6 到 16 位范围内</li>
</ol>
<h2 id="1-正则表达式语法">1 正则表达式语法</h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-markdown" data-lang="markdown">.           匹配任意字符（不包括换行符）
^           匹配开始位置，多行模式下匹配每一行的开始
$           匹配结束位置，多行模式下匹配每一行的结束
<span style="font-style:italic">*            匹配前一个元字符0到多次
</span><span style="font-style:italic">+            匹配前一个元字符1到多次
</span><span style="font-style:italic">?           匹配前一个元字符0到1次
</span><span style="font-style:italic">{m,n}       匹配前一个元字符m到n次
</span><span style="font-style:italic">\           转义字符，例如\.只能匹配.
</span><span style="font-style:italic">[]          字符集，一个字符的集合，可匹配其中任意一个字符
</span><span style="font-style:italic">\d          匹配一个数字， 相当于 [0-9]
</span><span style="font-style:italic">\D          匹配非数字,相当于 [^0-9]
</span><span style="font-style:italic">\s          匹配任意空白字符， 相当于 [ \t\n\r\f\v]
</span><span style="font-style:italic">\S          匹配非空白字符，相当于 [^ \t\n\r\f\v]
</span><span style="font-style:italic">\w          匹配数字、字母、下划线中任意一个字符， 相当于 [a-zA-Z0-9_</span>]
\W          匹配非数字、字母、下划线中的任意字符，相当于 [^a-zA-Z0-9_]
|           逻辑表达式 或 ，比如 a|b 代表可匹配 a 或者 b
(...)       分组
</code></pre></div><p>这些东西，记不住不重要，只要使用时查资料，能够理解使用就好。</p>
<p>接下来就是python中re模块如何使用正则表达式。</p>
<h2 id="2-recompile方法">2 re.compile方法</h2>
<p>该方法能够对一个匹配模式进行对象化，以方便后面平凡的调用：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#f92672">import</span> re <span style="color:#75715e"># 后面不再导入</span>
patt <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>compile(pattern,flags<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>) <span style="color:#75715e">#pattern为正则表达式</span>
</code></pre></div><p>参数：</p>
<p>pattern：正则表达式，时使用正则语法编写的字符串，使用为了防止转义可以使用原字符串(r&rsquo;xxx&rsquo;)</p>
<p>flags: 编译标志位，用来修改正则表达式的匹配方式，如：大小写区分，换行处理等</p>
<h2 id="3-rematch方法">3 re.match方法</h2>
<p>该方法从起始位置开始匹配，返回None或者re.Match对象</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#f92672">import</span> re
<span style="color:#75715e">#re模块match方法，参数：pattern：正则表达式，string：处理字符串</span>
re<span style="color:#f92672">.</span>match(pattern, string, flags<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>)
<span style="color:#75715e">#re.Pattern对象，该对象可以由compile（）生成，match方法，参数：string：处理字符串</span>
re<span style="color:#f92672">.</span>Pattern<span style="color:#f92672">.</span>match(string, pos<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>, endpos<span style="color:#f92672">=...</span>)

<span style="color:#75715e">#案例 ：密码匹配</span>
<span style="color:#75715e">#要求：</span>
<span style="color:#75715e">#	1.不能包含！@#￥%^&amp;*这些特殊符号</span>
<span style="color:#75715e">#	2.必须以字母开头</span>
<span style="color:#75715e">#	3.长度在 6 到 12 位范围内</span>
m <span style="color:#f92672">=</span> input(<span style="color:#e6db74">&#34;请输入密码：&#34;</span>)
m1<span style="color:#f92672">=</span>re<span style="color:#f92672">.</span>match(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;^\[A-Z]{1}[a-z0-9A-Z_]{6,12}&#39;</span>,m)
pint(m1)
<span style="color:#75715e">#输出结果如：&lt;re.Match object; span=(0, 1), match=&#39;xx&#39;&gt;</span>
<span style="color:#75715e">#span表示匹配的位子，左开右闭区间</span>
<span style="color:#75715e">#match表示匹配的字符</span>
</code></pre></div><p>match方法中结果的获取：</p>
<table>
<thead>
<tr>
<th>方法</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>ma.end(group=0, /)</td>
<td>返回指定分组的结束位置</td>
</tr>
<tr>
<td>ma.start(group=0, /)</td>
<td>返回指定分组的开始位置</td>
</tr>
<tr>
<td>ma.span(group=0, /)</td>
<td>返回指定分组开始与结束位置</td>
</tr>
<tr>
<td>ma.group([group1, &hellip;])</td>
<td>返回字符串或者元组</td>
</tr>
<tr>
<td>ma.groups(default=None)</td>
<td>返回所有分组信息</td>
</tr>
<tr>
<td>groupdict([default=None])</td>
<td>根据key获取分组信息</td>
</tr>
</tbody>
</table>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#75715e">#案例</span>
<span style="color:#f92672">import</span> re
<span style="color:#75715e">#正则表达式：匹配内容：数字+a~z+数字，并且进行分组</span>
ma <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>match(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;(\d)\w*(\d)&#39;</span>, <span style="color:#e6db74">&#39;1c3&#39;</span>)
<span style="color:#75715e">#匹配结果：&#39;1c3&#39;</span>
<span style="color:#66d9ef">print</span>(<span style="color:#e6db74">&#39;group():&#39;</span>, ma<span style="color:#f92672">.</span>group())
<span style="color:#75715e">#获取指定分组：1</span>
<span style="color:#66d9ef">print</span>(<span style="color:#e6db74">&#39;group(1):&#39;</span>, ma<span style="color:#f92672">.</span>group(<span style="color:#ae81ff">1</span>)) 
<span style="color:#75715e">#获取多个分组：(&#39;1&#39;, &#39;3&#39;)</span>
<span style="color:#66d9ef">print</span>(<span style="color:#e6db74">&#39;group(1,2):&#39;</span>, ma<span style="color:#f92672">.</span>group(<span style="color:#ae81ff">1</span>,<span style="color:#ae81ff">2</span>))
<span style="color:#75715e">#获取所有分组：(&#39;1&#39;, &#39;3&#39;)</span>
<span style="color:#66d9ef">print</span>(<span style="color:#e6db74">&#39;groups():&#39;</span>, ma<span style="color:#f92672">.</span>groups())
<span style="color:#75715e">#获取匹配结果索引：(0, 3)</span>
<span style="color:#66d9ef">print</span>(<span style="color:#e6db74">&#39;span():&#39;</span>, ma<span style="color:#f92672">.</span>span())
<span style="color:#75715e">#获取指定分组索引：(0, 1)</span>
<span style="color:#66d9ef">print</span>(<span style="color:#e6db74">&#39;span(1):&#39;</span>,ma<span style="color:#f92672">.</span>span(<span style="color:#ae81ff">1</span>))
</code></pre></div><p>输出结果：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-text" data-lang="text">group(): 1c3
group(1): 1
group(1,2): (&#39;1&#39;, &#39;3&#39;)
groups(): (&#39;1&#39;, &#39;3&#39;)
span(): (0, 3)
span(1): (0, 1)
</code></pre></div><h2 id="4-research方法">4 re.search方法</h2>
<p>该方法用于在字符串中查找，返回match对象或者None</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">search(pattern, string, flags<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>) <span style="color:#75715e">#参数与match类似。</span>
</code></pre></div><p>练习：查找第一次出现的数字组成的字串:<br />
在字符串：&lsquo;pay:2000 date:2019-03-04&rsquo;，找到支付价格：2000；</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">s <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;pay:2000 date:2019-03-04&#39;</span>
<span style="color:#75715e">#\d+：匹配数字一次或者多次</span>
ma <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>search(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;pay:\d+&#39;</span>, s)
<span style="color:#66d9ef">print</span>(ma)
</code></pre></div><p>输出结果：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#f92672">&lt;</span>re<span style="color:#f92672">.</span>Match object; span<span style="color:#f92672">=</span>(<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">8</span>), match<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;pay:2000&#39;</span><span style="color:#f92672">&gt;</span>
</code></pre></div><h2 id="5-refindallfinditer方法">5 re.findall/finditer方法</h2>
<p>re.findall：在字符串中根据正则表达式查找所有匹配，返回查找结果组成列表；<br />
re.finditer与findall功能相同，返回自迭代器；</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">re<span style="color:#f92672">.</span>findall(pattern, string, flags<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>) 
</code></pre></div><p>案例：查找字符串中所有数字字符串</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#f92672">import</span> re
s <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;pay:2000 date:2019-03-04&#39;</span>
result <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>findall(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;\d+&#39;</span>, s)
<span style="color:#66d9ef">print</span>(result)
</code></pre></div><p>结果为列表：[&lsquo;2000&rsquo;, &lsquo;2019&rsquo;, &lsquo;03&rsquo;, &lsquo;04&rsquo;]；</p>
<h2 id="6-resplit方法">6 re.split方法</h2>
<p>该方法将字符串中根据正则表达式查找匹配字符串，然后进行切分，返回字串列表；</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">re<span style="color:#f92672">.</span>split(pattern, string, maxsplit<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>, flags<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>)
<span style="color:#75715e">#maxsplit：切分次数，默认所有匹配都切分</span>
</code></pre></div><p>练习：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">info <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;student:huang,  id:64  age 19&#39;</span>
<span style="color:#960050;background-color:#1e0010">整理格式：</span>
dinfo <span style="color:#f92672">=</span> {<span style="color:#e6db74">&#39;student&#39;</span>:<span style="color:#e6db74">&#39;huang&#39;</span>, <span style="color:#e6db74">&#39;id&#39;</span>:<span style="color:#e6db74">&#39;64&#39;</span>, <span style="color:#e6db74">&#39;age&#39;</span>:<span style="color:#e6db74">&#39;19&#39;</span>}
</code></pre></div><p>分析：</p>
<blockquote>
<p>1&gt;对info使用非字母，数字进行切分；<br />
2&gt;切分后将其整理成字典；</p>
</blockquote>
<p>第一步切分：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">info <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;system:linux, cpu:x64 memory 8G&#39;</span>
<span style="color:#75715e">#正则表达式：\W+，匹配1个或多个</span>
s <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>split(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;\W+&#39;</span>,info)
<span style="color:#66d9ef">print</span>(s)
</code></pre></div><p>切分结果：[&lsquo;system&rsquo;, &lsquo;linux&rsquo;, &lsquo;cpu&rsquo;, &lsquo;x64&rsquo;, &lsquo;memory&rsquo;, &lsquo;8G&rsquo;]；<br />
第二步整理字典：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">info <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;system:linux, cpu:x64 memory 8G&#39;</span>
s <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>split(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;\W+&#39;</span>,info)
dinfo <span style="color:#f92672">=</span> {}
<span style="color:#66d9ef">for</span> index <span style="color:#f92672">in</span> range(<span style="color:#ae81ff">0</span>, len(s), <span style="color:#ae81ff">2</span>):
    dinfo[s[index]] <span style="color:#f92672">=</span> s[index<span style="color:#f92672">+</span><span style="color:#ae81ff">1</span>]
<span style="color:#66d9ef">print</span>(dinfo)
</code></pre></div><p>输出结果：{&lsquo;system&rsquo;: &lsquo;linux&rsquo;, &lsquo;cpu&rsquo;: &lsquo;x64&rsquo;, &lsquo;memory&rsquo;: &lsquo;8G&rsquo;}</p>
<h2 id="7-resub与resubn">7 re.sub与re.subn</h2>
<p>re.sub与re.subn实现的字符串替换功能；</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">re<span style="color:#f92672">.</span>sub(pattern, repl, string, count<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>, flags<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>)
re<span style="color:#f92672">.</span>subn(pattern, repl, string, count<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>, flags<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>)
</code></pre></div><p>re.sub方法根据正则表达式将匹配子串替换成设置值并返回新字符串；参数如下：</p>
<table>
<thead>
<tr>
<th>主要参数</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>pattern</td>
<td>正则表达式</td>
</tr>
<tr>
<td>repl</td>
<td>替换内容，可以是字符串或者函数</td>
</tr>
<tr>
<td>string</td>
<td>处理字符串</td>
</tr>
<tr>
<td>count</td>
<td>替换数量</td>
</tr>
</tbody>
</table>
<p>re.subn与re.sub类似，返回替换数量与新字符串；</p>
<p>练习：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">s  <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;user:sun,pwd:222222&#34;</span><span style="color:#960050;background-color:#1e0010">，将密码：</span><span style="color:#ae81ff">222222</span> <span style="color:#960050;background-color:#1e0010">替换为：</span><span style="color:#f92672">******</span><span style="color:#960050;background-color:#1e0010">；</span>
</code></pre></div><p>可以直接使用字符串替换方法：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">s<span style="color:#f92672">.</span>replace(<span style="color:#e6db74">&#39;222222&#39;</span>, <span style="color:#e6db74">&#39;******&#39;</span>)
<span style="color:#75715e">#结果：&#39;user:sun,pwd:******&#39;</span>
</code></pre></div><p>如果密码为不一样数字如何替换？例如：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">s  <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;user:sun,pwd:234567&#34;</span>
</code></pre></div><p>使用re.sub方法：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#75715e">#将pwd:xxxx替换成******</span>
re<span style="color:#f92672">.</span>sub(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;pwd:(\d+)&#39;</span>, <span style="color:#e6db74">&#34;******&#34;</span>, s)
<span style="color:#75715e">#结果：&#39;user:sun,******&#39;</span>
</code></pre></div><p>问题：pwd:去哪里了？如何处理？使用分组。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#75715e">#pattern使用两个分组</span>
<span style="color:#75715e">#repl为原字符串，\1代表第一个分组内容，</span>
re<span style="color:#f92672">.</span>sub(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;(pwd:)(\d+)&#39;</span>, <span style="color:#e6db74">r</span><span style="color:#e6db74">&#34;\1******&#34;</span>, s)
</code></pre></div><p>替换结果：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#e6db74">&#39;user:sun,pwd:******&#39;</span>
</code></pre></div><p>大家可以理解下这个题目。</p>
<p>新的问题来了，一组考试成绩：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">s <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;math:90, chinese:90, english:50&#39;</span>
</code></pre></div><p>大于等于60，替换成Pass，否则替换成Faild；推荐使用正则。</p>
<p>我们可以使用函数功能，先来看匹配分数，将其替换为空字符串；</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">re<span style="color:#f92672">.</span>sub(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;\d+&#39;</span>, <span style="color:#e6db74">&#39;&#39;</span>, s)
</code></pre></div><p>结果：&lsquo;math:, chinese:, english:'；<br />
我们将repl替换成函数，函数有一个参数，返回值为空字符串；</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">func</span>(arg):
    <span style="color:#66d9ef">print</span>(arg)
    <span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#39;&#39;</span>
re<span style="color:#f92672">.</span>sub(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;\d+&#39;</span>, func, s)
</code></pre></div><p>输出结果：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#f92672">&lt;</span>_sre<span style="color:#f92672">.</span>SRE_Match object; span<span style="color:#f92672">=</span>(<span style="color:#ae81ff">5</span>, <span style="color:#ae81ff">7</span>), match<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;90&#39;</span><span style="color:#f92672">&gt;</span>
<span style="color:#f92672">&lt;</span>_sre<span style="color:#f92672">.</span>SRE_Match object; span<span style="color:#f92672">=</span>(<span style="color:#ae81ff">17</span>, <span style="color:#ae81ff">19</span>), match<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;90&#39;</span><span style="color:#f92672">&gt;</span>
<span style="color:#f92672">&lt;</span>_sre<span style="color:#f92672">.</span>SRE_Match object; span<span style="color:#f92672">=</span>(<span style="color:#ae81ff">29</span>, <span style="color:#ae81ff">31</span>), match<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;50&#39;</span><span style="color:#f92672">&gt;</span>
<span style="color:#e6db74">&#39;math:, chinese:, english:&#39;</span>
</code></pre></div><p>可以看到func中参数为每个匹配的match对象，我们可以获取这个值，并对其处理。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">func</span>(arg):
    <span style="color:#75715e">#获取分数</span>
    score <span style="color:#f92672">=</span> int(arg<span style="color:#f92672">.</span>group())
    <span style="color:#75715e">#重置返回结果</span>
    <span style="color:#66d9ef">if</span> score <span style="color:#f92672">&lt;</span><span style="color:#ae81ff">60</span>:
        <span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#39;Faild&#39;</span>
    <span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#39;Pass&#39;</span>
re<span style="color:#f92672">.</span>sub(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;\d+&#39;</span>, func, s)
</code></pre></div><p>输出结果：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#e6db74">&#39;math:Pass, chinese:Pass, english:Faild&#39;</span>
</code></pre></div><h2 id="8-flags标志位">8 flags标志位:</h2>
<p>match，split等方法中都有一个标志位，主要设置值如下：</p>
<table>
<thead>
<tr>
<th>flag值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>re.I/re.IGNORECASE</td>
<td>匹配不区分大小写</td>
</tr>
<tr>
<td>re.L/re.LOCALE</td>
<td>\w, \W, \b, \B, \s and \S 依赖于本地</td>
</tr>
<tr>
<td>re.M/re.MULTILINE</td>
<td>多行匹配，对'^'与'$'有影响</td>
</tr>
<tr>
<td>re.S/re.DOTALL</td>
<td>使&rsquo;.&lsquo;特殊字符匹配任何字符</td>
</tr>
<tr>
<td>re.U/re.UNICODE</td>
<td>根据Unicode字符集解析字符。\w, \W, \b, \B, \d, \D, \s和 \S 取决于UNICODE定义的字符属性</td>
</tr>
<tr>
<td>re.X/re.VERBOSE</td>
<td>此标志允许您编写正则表达式，可添加注释</td>
</tr>
</tbody>
</table>
<p>这些标志位可以结合使用，例如：re.M | re.S。<br />
每个标志使用案例与对比如下：</p>
<h3 id="rei匹配忽略大小写">re.I：匹配忽略大小写</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">ma <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>match(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;name:\w+&#39;</span>, <span style="color:#e6db74">&#39;Name:sun age:10&#39;</span>)
<span style="color:#66d9ef">print</span>(ma)
<span style="color:#75715e">#添加re.I标志</span>
ma <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>match(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;name:\w+&#39;</span>, <span style="color:#e6db74">&#39;Name:sun age:10&#39;</span>, re<span style="color:#f92672">.</span>I)
<span style="color:#66d9ef">print</span>(ma)
</code></pre></div><p>结果：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">None
<span style="color:#f92672">&lt;</span>re<span style="color:#f92672">.</span>Match object; span<span style="color:#f92672">=</span>(<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">8</span>), match<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;Name:sun&#39;</span><span style="color:#f92672">&gt;</span>
</code></pre></div><h3 id="rem多行匹配">re.M：多行匹配</h3>
<p>找到字符串中与户名</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#75715e">#注意，中间的换行\n</span>
s <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Name:sun age:10</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">name:liu, age:9&#39;</span>
<span style="color:#75715e">#正则表达式：每行开头开始匹配，默认处理第一行</span>
result <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>findall(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;^name:\w+&#39;</span>, s, re<span style="color:#f92672">.</span>I)
<span style="color:#66d9ef">print</span>(result)
</code></pre></div><p>输出结果：[&lsquo;Name:sun&rsquo;]；我们想要找到所有用户名？添加re.M，代码如下：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">s <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Name:sun age:10</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">name:liu, age:9&#39;</span>
<span style="color:#75715e">#re.I | re.M,支持设置多个标志位</span>
result <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>findall(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;^name:\w+&#39;</span>, s, re<span style="color:#f92672">.</span>I<span style="color:#f92672">|</span>re<span style="color:#f92672">.</span>M)
<span style="color:#66d9ef">print</span>(result)
</code></pre></div><p>结果：[&lsquo;Name:sun&rsquo;, &lsquo;name:liu&rsquo;]</p>
<h2 id="res-修改的行为">re.S 修改&rsquo;.&lsquo;的行为</h2>
<p>字符串：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">what <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;I Say:&#34;No!</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">No!&#34;&#39;</span>
</code></pre></div><p>找出我说的话：&ldquo;No!\nNo!&rdquo;<br />
匹配规则，双引号中间字符串，实现：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">what <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;I Say:&#34;No!</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">No!&#34;&#39;</span>
ma <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>search(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;\&#34;.+\&#34;&#39;</span>, what)
<span style="color:#66d9ef">print</span>(ma)
</code></pre></div><p>输出结果：None；因为&rsquo;.&lsquo;不能匹配&rsquo;\n&rsquo;，设置标志re.S，实现：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python">what <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;I Say:&#34;No!</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">No!&#34;&#39;</span>
ma <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>search(<span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;\&#34;.+\&#34;&#39;</span>, what, re<span style="color:#f92672">.</span>S)
<span style="color:#66d9ef">print</span>(ma)
</code></pre></div><p>输出结果：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#f92672">&lt;</span>re<span style="color:#f92672">.</span>Match object; span<span style="color:#f92672">=</span>(<span style="color:#ae81ff">6</span>, <span style="color:#ae81ff">15</span>), match<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;&#34;No!</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">No!&#34;&#39;</span><span style="color:#f92672">&gt;</span>
</code></pre></div><p>转载自https://blog.51cto.com/huangyg/2376894</p>
  </div>
  <footer>
    <ul class="stats">
  
    
    
      <li class="categories">
        <ul>
          
            
            <li><a class="article-category-link" href="https://hhs44.github.io/categories/python">python</a></li>
          
        </ul>
      </li>
    
  
  
    
    
      <li class="tags">
        <ul>
          
            
            <li><a class="article-category-link" href="https://hhs44.github.io/tags/re">re</a></li>
          
        </ul>
      </li>
    
  
</ul>

  </footer>
</article>

    <article class="post">
      
<div>
  <h2>说些什么</h2>
    <form id="post-js-form" class="post-new-comment" method="POST">
      
      <h5 class='post-reply-notice hidden'>
        <span class='post-reply-arrow'></span><span class='post-reply-name'></span>
      </h5>

      
      <input type="hidden" name="options[entryId]" value="097623e45d6510c7d667ec96ae3c8ceb">
      <input type='hidden' name='fields[replyThread]' value=''>
      <input type='hidden' name='fields[replyID]' value=''>
      <input type='hidden' name='fields[replyName]' value=''>

      
      <input required name='fields[name]' type='text' placeholder='您的名字（必填）'>
      <input name='fields[website]' type='text' placeholder='您的网站'>
      <input required name='fields[email]' type='email' placeholder='您的电邮地址（必填，用于 Gravatar 头象）'>
      <textarea required name='fields[body]' placeholder='您的留言。可使用 Markdown。（搜索 &#39;Markdown 語法速查&#39;）' rows='10'></textarea>

      
      

      
      <p class='post-submit-notice'>
        <strong class='post-submit-notice-text submit-success hidden'>感谢您的评论！被批准后它会立即在此站点展示。</strong>
        <strong class='post-submit-notice-text submit-failed hidden'>很抱歉，您的提交存在错误。请确保所有必填字段都已填写正确，然后再试一次。</strong>
      </p>

      
      <input type='submit' value='送出' class='button'>
      <input type='submit' value='已送出' class='hidden button' disabled>
      <input type='reset' value='重设' class='button'>
    </form>
</div>


<div>
  <h2>评论</h2>

  
    
      <p>还沒有留言。</p>
    
  
</div>

    </article>


<div class="pagination">
  
    <a href="/blog/my-first-blog/" class="button"><div class="previous"><div>My First Blog</div></div></a>
  
  
    <a href="/blog/markdown-reference-/" class="button"><div class="next"><div>Markdown For Typora</div></div></a>
  
</div>


      </main>
      <div class="post-toc">
     
    <aside>
        <header>
        <h4>python3 正则表达式的字数: 553</h4> 
        </header><nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li><a href="#1-正则表达式语法">1 正则表达式语法</a></li>
        <li><a href="#2-recompile方法">2 re.compile方法</a></li>
        <li><a href="#3-rematch方法">3 re.match方法</a></li>
        <li><a href="#4-research方法">4 re.search方法</a></li>
        <li><a href="#5-refindallfinditer方法">5 re.findall/finditer方法</a></li>
        <li><a href="#6-resplit方法">6 re.split方法</a></li>
        <li><a href="#7-resub与resubn">7 re.sub与re.subn</a></li>
        <li><a href="#8-flags标志位">8 flags标志位:</a>
          <ul>
            <li><a href="#rei匹配忽略大小写">re.I：匹配忽略大小写</a></li>
            <li><a href="#rem多行匹配">re.M：多行匹配</a></li>
          </ul>
        </li>
        <li><a href="#res-修改的行为">re.S 修改&rsquo;.&lsquo;的行为</a></li>
      </ul>
    </li>
  </ul>
</nav></aside>
    <a href="#" id="toc-toggle"></a>
     
</div>
      <section id="site-sidebar">
  
    <section id="recent-posts">
      <header>
        <h1>最新文章</h1>
      </header>
      
      <article class="mini-post">
        <section>
          
  <a href="/blog/css%E5%AD%A6%E4%B9%A0%E4%B8%80/" class="image featured">
    
      <img src="https://raw.githubusercontent.com/hhs44/cloudimg/master/img/20200331114355.png" alt="">
    
  </a>


        </section>
        <header>
          <h1><a href="/blog/css%E5%AD%A6%E4%B9%A0%E4%B8%80/">CSS学习一</a></h1>
          <time class="published" datetime="">March 31, 2020</time>
        </header>
      </article>
      
      <article class="mini-post">
        <section>
          
  <a href="/blog/html%E5%AD%A6%E4%B9%A0%E4%B8%80/" class="image featured">
    
      <img src="https://raw.githubusercontent.com/hhs44/cloudimg/master/img/20200331114355.png" alt="">
    
  </a>


        </section>
        <header>
          <h1><a href="/blog/html%E5%AD%A6%E4%B9%A0%E4%B8%80/">HTML学习一</a></h1>
          <time class="published" datetime="">March 31, 2020</time>
        </header>
      </article>
      
      <article class="mini-post">
        <section>
          
  <a href="/blog/web%E5%9F%BA%E7%A1%80/" class="image featured">
    
      <img src="https://raw.githubusercontent.com/hhs44/cloudimg/master/img/20200331114355.png" alt="">
    
  </a>


        </section>
        <header>
          <h1><a href="/blog/web%E5%9F%BA%E7%A1%80/">web基础</a></h1>
          <time class="published" datetime="">March 31, 2020</time>
        </header>
      </article>
      
      
        <a href="/blog/" class="button">查看更多</a>
      
    </section>
  

  
    
      <section id="categories">
        <header>
          <h1><a href="/categories">分类</a></h1>
        </header>
        <ul>
          
            
          
          
          <li>
            
              <a href="/categories/python/">python<span class="count">6</span></a>
            
          
          <li>
            
              <a href="/categories/linux/">linux<span class="count">4</span></a>
            
          
          <li>
            
              <a href="/categories/web/">web<span class="count">4</span></a>
            
          
          <li>
            
              <a href="/categories/hexo/">hexo<span class="count">3</span></a>
            
          
          <li>
            
              <a href="/categories/jetbrain/">jetbrain<span class="count">2</span></a>
            
          
          <li>
            
              <a href="/categories/test/">test<span class="count">2</span></a>
            
          
          <li>
            
              <a href="/categories/%E5%89%8D%E7%AB%AF/">前端<span class="count">2</span></a>
            
          
          <li>
            
              <a href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库<span class="count">2</span></a>
            
          
          <li>
            
              <a href="/categories/conda/">conda<span class="count">1</span></a>
            
          
          <li>
            
              <a href="/categories/development/">development<span class="count">1</span></a>
            
          
          <li>
            
              <a href="/categories/golang/">golang<span class="count">1</span></a>
            
          
          <li>
            
              <a href="/categories/java/">java<span class="count">1</span></a>
            
          
          <li>
            
              <a href="/categories/syntax/">syntax<span class="count">1</span></a>
            
          
          <li>
            
              <a href="/categories/%E9%80%9A%E4%BF%A1/">通信<span class="count">1</span></a>
            
          
          </li>
        </ul>
      </section>
    
  

  
    <section id="mini-bio">
      <header>
        <h1>关于</h1>
      </header>
      <p>test</p>
      <footer>
        <a href="/about" class="button">了解更多</a>
      </footer>
    </section>
  
</section>

      <footer id="site-footer">
  
      <ul class="socnet-icons">
        

        <li><a href="//github.com/hhs44/hhs44.github.io" target="_blank" rel="noopener" title="GitHub" class="fab fa-github"></a></li>






<li><a href="//flickr.com/photos/example" target="_blank" rel="noopener" title="Flickr" class="fab fa-flickr"></a></li>




<li><a href="//linkedin.com/in/example" target="_blank" rel="noopener" title="LinkedIn" class="fab fa-linkedin"></a></li>
<li><a href="//linkedin.com/company/examplebusiness" target="_blank" rel="noopener" title="LinkedIn Company" class="fab fa-linkedin"></a></li>



<li><a href="//facebook.com/example" target="_blank" rel="noopener" title="Facebook" class="fab fa-facebook"></a></li>
<li><a href="//reddit.com/user/example" target="_blank" rel="noopener" title="Reddit" class="fab fa-reddit"></a></li>





<li><a href="weixin://contacts/profile/22" target="_blank" rel="noopener" title="WeChat" class="fab fa-weixin"></a></li>
<li><a href="//wpa.qq.com/msgrd?v=3&amp;uin=1159986871&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener" title="QQ" class="fab fa-qq"></a></li>
<li><a href="//instagram.com/example" target="_blank" rel="noopener" title="Instagram" class="fab fa-instagram"></a></li>

<li><a href="//twitter.com/example" target="_blank" rel="noopener" title="Twitter" class="fab fa-twitter"></a></li>


<li><a href="//pinterest.com/example" target="_blank" rel="noopener" title="Pinterest" class="fab fa-pinterest-p"></a></li>
<li><a href="//telegram.me/example" target="_blank" rel="noopener" title="telegram" class="fab fa-telegram"></a></li>



<li><a href="//researchgate.net/profile/example" target="_blank" rel="noopener" title="Research Gate"><i class="ai ai-researchgate"></i></a></li>
<li><a href="//keybase.io/example" target="_blank" rel="noopener" title="keybase" class="fab fa-keybase"></a></li>
<li><a href="//example.com/@example" target="_blank" rel="noopener" title="mastodon" class="fab fa-mastodon"></a></li>
<li><a href="mailto:1159986871@qq.com" target="_blank" title="Email" class="far fa-envelope"></a></li>

      </ul>
  
  <p class="copyright">
    
      &copy; 2020
      
        Huanghs blog
      
    . <br>
    主题: <a href='https://themes.gohugo.io/hugo-future-imperfect-slim/' target='_blank' rel='noopener'>Hugo Future Imperfect Slim</a><br>移植自 <a href='https://html5up.net/future-imperfect' target='_blank' rel='noopener'>HTML5 UP</a> | 由 <a href='https://gohugo.io/' target='_blank' rel='noopener' title='0.66.0'>Hugo</a> 驱动
  </p>
</footer>
<a id="back-to-top" href="#" class="fas fa-arrow-up fa-2x"></a>

      <script src="/js/highlight.pack.js"></script>
    <script>hljs.initHighlightingOnLoad();</script><script src="/js/bundle.min.b17fef5a58c033a8a59f57c83aa975a251aecff921cbd36c12e975d530fa023b.js" integrity="sha256-sX/vWljAM6iln1fIOql1olGuz/khy9NsEul11TD6Ajs="></script>
    <script src="/js/add-on.js"></script>
    </div>
  </body>
</html>
